package cn.java86;
//import com.mysql.cj.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class Jdbc3 {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return;
        }
        //修改学生信息，根据学号，改名字和QQ号

        Scanner in = new Scanner(System.in);
        System.out.println("请输入学号：");
        long stuno = in.nextLong();
        in.nextLine();
        System.out.println("姓名：");
        String name = in.nextLine();
        //        name=name.replaceAll("#","");
        //        name=name.replaceAll("--","");
        //? %
        System.out.println("QQ：");
        String qq = in.next();
        //?参数
        String url = "jdbc:mysql://localhost:3308/java86school?useUnicode=true&characterEncoding=utf8&useSSL=false" +
                "&serverTimezone=GMT%2B8";
        String user = "root";
        String pass = "root1234";
        Connection con = null;
        Statement st = null;
        try {
            con = DriverManager.getConnection(url, user, pass);
            st = con.createStatement();
            String sql ="update s_student set sname='" + name + "' ,qq='" + qq + "' where stuno=" + stuno ;
            System.out.println(sql);
            int i = st.executeUpdate(sql);
            System.out.println("成功修改" + i + "条记录");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (st != null)
                    st.close();
            } catch (Exception e) {
                //e.printStackTrace();
            }
            try {
                con.close();
            } catch (Exception e) {
                //e.printStackTrace();
            }
        }
    }
}
